package org.usyk;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * User: Алексейка
 * Date: 28.03.12
 * Time: 20:54
 */
public class Coalition {
    
    private Map<Integer, String> participants = new HashMap<Integer, String>();
    private String mask;
    private int groupNumber;
    private double preRating;
    private double gain;

    public Coalition() {
    }

    public Coalition(Map.Entry<Integer,String> entry) {
        participants.put(entry.getKey(),entry.getValue());
    }

    public Coalition(Map<Integer, String> participants, String mask, int groupNumber, double preRating, double gain) {
        for (Map.Entry<Integer,String> partyEntry : participants.entrySet()) {
            this.participants.put(partyEntry.getKey(), partyEntry.getValue());
        }
        this.mask = mask;
        this.groupNumber = groupNumber;
        this.preRating = preRating;
        this.gain = gain;
    }
    
    public Coalition(Coalition c) {
        this(c.getParticipants(),c.getMask(),c.getGroupNumber(),c.getPreRating(),c.getGain());
    }

    public Set<Integer> getParticipantsSet() {
        return participants.keySet();
    }

    public Map<Integer, String> getParticipants() {
        return participants;
    }

    public String getMask() {
        return mask;
    }

    public void setMask(String mask) {
        this.mask = mask;
    }

    public int getGroupNumber() {
        return groupNumber;
    }

    public void setGroupNumber(int groupNumber) {
        this.groupNumber = groupNumber;
    }

    public double getPreRating() {
        return preRating;
    }

    public void setPreRating(double preRating) {
        this.preRating = preRating;
    }

    public double getGain() {
        return gain;
    }

    public void setGain(double gain) {
        this.gain = gain;
    }

    public void addPaticipant(Integer participant, String name) {
        participants.put(participant, name);
    }
    
    public void excludeParticipant(Integer participant){
        participants.remove(participant);
    }

    public int size() {
        return participants.size();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Coalition coalition = (Coalition) o;

        if (participants != null ? !participants.equals(coalition.participants) : coalition.participants != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        return participants != null ? participants.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "Coalition{" +
                "gain=" + String.format("%.2f",gain) +
                ", participants=" + participants.values() +
                '}';
    }
}
